import _ from 'lodash';
import model from '../models/one';

console.log('reducer init start');

const  {
  state: initState,
  subscriptions,
  effects,
  reducers,
} = model;

const reducer = (state = initState, action) => {
  const { type } = action;
  if (_.isFunction(reducers[type])) {
    return reducers[type](state, action);
  } else {
    return state;
  }
}

function * sages() {
  yield _.map(effects, function *({ effect, name }) {
    yield* takeEvery(name, effect);
  });
}

console.log('reducer init end');

export default reducer;